<?php
/**
* phpCan - http://idc.anavallasuiza.com/
*
* phpCan is released under the GNU Affero GPL version 3
*
* More information at license.txt
*/

defined('ANS') or die();

if ($info['data']['']) {
	echo $Form->checkbox(array(
		'name' => $info['varname'].'[0]',
		'force' => false,
		'value' => 1,
		'label_text' => __('Delete file')
	));
	
	echo '&nbsp;&nbsp;&nbsp;';
}
?>

<?php
echo $Form->file(array(
	'name' => $info['varname'].'[0]',
	'id' => $info['id_field'],
	'error' => $info['error']['']
));
?>

&nbsp;&nbsp;&nbsp;

<span class="link" id="<?php echo $info['id_field'] ?>_url"><?php __e('Upload image from an url'); ?></span>
<span class="link hide" id="<?php echo $info['id_field'] ?>_computer"><?php __e('Upload image from my computer'); ?></span>

&nbsp;&nbsp;&nbsp;

<?php
if ($info['data']['']) {
	echo $Html->a(array(
		'text' => __('View file'),
		'href' => $Html->imgSrc($info['data']['']),
		'target' => '_blank',
		'class' => 'link'
	));
}
?>

<script type="text/javascript">
	$(document).ready(function () {
		$('#<?php echo $info['id_field']; ?>_url').click(function () {
			$('#<?php echo $info['id_field']; ?>').changeInputType('url');
			$(this).hide();
			$('#<?php echo $info['id_field']; ?>_computer').show();

			return false;
		});

		$('#<?php echo $info['id_field']; ?>_computer').click(function () {
			$('#<?php echo $info['id_field']; ?>').changeInputType('file');
			$(this).hide();
			$('#<?php echo $info['id_field']; ?>_url').show();

			return false;
		});
	});
</script>
